﻿@{
    Layout = "../Shared/_InnerPage.cshtml";
}
@model XoohooViewModelItem<IPagedList<UserBasic>>
@section TitleContent{
    @Html.SiteTitle("系统管理", "用户管理", "用户信息管理", "用户信息列表")
}
@section HeadCustom{
    <style type="text/css">
        ul, li
        {
            padding: 0px;
            margin: 0px;
            list-style-type: none;
        }
        .control
        {
            cursor: pointer;
        }
        .controlMenu
        {
            cursor: pointer;
            color:#fff;
            background-color: #596162;
            border: 1px solid #373D3E;
            position: absolute;
            display: none;
        }
        .controlMenu li
        {
            line-height: 20px;
            text-align: center;
        }
        .controlMenu .over
        {
            background-color: #4D5455;
            color: #cccccc;
        }
    </style>
    <script language="javascript" type="text/javascript">
        $(document).ready(function () {
            $(".delete>a").click(function () {
                if (!confirm("删除该用户只是将其标示为\"删除状态\"。\n确定要删除该用户？")) { return false; }
            });

            // 状态选择

            $("ul.controlMenu").bind("mouseleave", function () {
                $(this).hide();
            });
            $("ul.controlMenu li").hover(function () {
                $(this).addClass("over");
            }, function () {
                $(this).removeClass("over");
            }
        );
            $("ul.controlMenu li").click(function () {
                action($(this).attr("command"), currentController.attr("value"), $(this).attr("v"), $(this).text());
                $(this).parent().hide();
            });


            var controlMenu = $("ul.controlMenu");
            var currentController;
            $("a.controller").click(function () {
                var parent = $(this).parent();
                controlMenu.css("top", parent.offset().top + 'px');
                controlMenu.css("left", parent.offset().left + 'px');
                controlMenu.width(parent.width());
                controlMenu.show();
                currentController = $(this);
            });

            // 单条命令调用
            var adminPath = '@Model.Site.AdminPath';
            if (adminPath) adminPath = "/" + adminPath;
            function action(command, id, value, text) {
                var url = "{0}/Membership/User/{1}/{2}/{3}?".format(adminPath, command, id, value);
                $.getJSON(url, { r: (new Date()).getTime() }, function (data) {
                    if (data.Result) {
                        if (currentController) {
                            currentController.text(text);
                        }
                    } else {
                        alert("修改用户状态失败！");
                    }

                });
                //window.location = url;

            }

        });
    </script>
}
@section NavigationContent
{
当前位置：用户管理 &gt;&gt; 用户信息管理 &gt;&gt; 用户信息列表
}
@{
    IPagedList<UserBasic> users = Model.Item;
    UserSearchCriteria criteria = Model.GetModelItem<UserSearchCriteria>();
    SelectList userGroups = Model.GetModelItem<SelectList>("UserGroups");
    SelectList status = Model.GetModelItem<SelectList>("UserStatus");
    SelectList pageSize = Model.GetModelItem<SelectList>("PageSize");

    var routeValues = new RouteValueDictionary(criteria);
    routeValues.Add("PageSize", users.PageSize);
    routeValues.Add("PageNumber", users.PageNumber);

    //用于分页跳转
    string currentUrl = Url.RouteUrl("Admin.Membership.User.UserList", routeValues);
    //用于显示全部
    string defaultUrl = Url.RouteUrl("Admin.Membership.User.UserList");

    //如果采用路由规则中的配置，BeginRouteForm的routeValues可以设为null
    Html.BeginRouteForm("Admin.Membership.User.UserList", null, FormMethod.Post, new { @id = "UserSearchForm", @name = "UserSearchForm" });
}
<table cellpadding="4" cellspacing="0" class="tbl">
    <tr>
        <td class="tit80">
            查找用户：
        </td>
        <td>
            @Html.TextBox("keyword", criteria.Keyword, new { @class = "input80 valignmiddle" })
            @Html.DropDownList("userGroupID", userGroups, "-用户组-", new { @class = "valignmiddle" })
            @Html.DropDownList("status", status, "-状态-", new { @class = "valignmiddle" })
            @Html.DropDownList("pageSize", pageSize, new { @class = "valignmiddle" })
            第
            @Html.TextBox("PageNumber", users.PageNumber, new { @class = "input20 valignmiddle" })
            页
            @Html.ImageButton("btnSearch", "Styles/Images/btnSearch.jpg", new { @class = "valignmiddle" })
            <a href="@defaultUrl">
                @Html.SkinImage("Styles/Images/btnViewAll.jpg", "", new { @class = "valignmiddle" })</a>
        </td>
    </tr>
</table>
@{Html.EndForm();}
@{
    if (!users.IsNullOrEmpty())
    {
        WriteLiteral(Html.Grid(users).Columns(column =>
        {
            column.For(item => Html.ActionLink(item.Username, "UserAddOrEdit", new { UserID = item.UserID })).Named("用户名").Encode(false).HeaderAttributes(@class => "tit80").Attributes(@class => "con80");
            column.For(item => item.DisplayName).Named("昵称").HeaderAttributes(@class => "tit80").Attributes(@class => "con80");
            column.For(item => item.UserGroup.UserGroupName).Named("所属用户组").HeaderAttributes(@class => "tit80").Attributes(@class => "con80");
            column.For(item => item.Email).Named("邮件").HeaderAttributes(@class => "titOth").Attributes(@class => "conOth");
            column.For(item => item.CreationDate).Named("创建日期").HeaderAttributes(@class => "tit120").Attributes(@class => "con120");
            column.For(item => Html.Link(item.Status.ToChinese(), "javascript:void(0);", new { @value = item.UserID, @class = "controller" })).Encode(false).Named("状态").HeaderAttributes(@class => "titCtr").Attributes(@class => "conCtr");
            column.For(item => Html.ActionLink("编辑", "UserAddOrEdit", new { UserID = item.UserID, ReturnUrl = currentUrl })).Encode(false).Attributes(@class => "conCtr");
            column.For(item => Html.ActionLink("删除", "UserRemove", new { UserID = item.UserID, ReturnUrl = currentUrl })).Encode(false).Attributes(@class => "conCtr delete").CellCondition(u => u.Status != UserStatus.Removed);
        })
            //表格属性
.Attributes(@class => "tbl")
            //表头行属性
.HeaderRowAttributes(new Hash(@class => "rowhead"))
            //列表行属性
.RowAttributes(data => new Hash(@class => "{0}".FormatWith(data.IsAlternate ? "rowodd" : ""))));
    }    
}
<div class="pager">
    @Html.Paging(users.PageSize, users.PageNumber, users.TotalItemCount, "UserList", criteria)
    <form action="@currentUrl" id="GotoPageForm" method="post" name="GotoPageForm">
    <br />
    跳转至页：@Html.TextBox("PageNumber", users.PageNumber, new { @class = "input20 valignmiddle" })
    @Html.ImageButton("btnGo", "Styles/Images/btnGo.jpg", new { @class = "valignmiddle" })
    </form>
</div>
<ul class="controlMenu">
    @{foreach (var item in status)
      {
          WriteLiteral("<li v=\"{0}\" command=\"ChangeStatus\">{1}</li>".FormatWith(item.Value, item.Text));
      }
    }
</ul>
